package Help.Manager.Album;

import photos.core.commons.Contants;
import photos.core.commons.PhotoHolder;

import com.example.easynote.R;


import DTO.AlbumModel;
import DTO.PhotoModel;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

/*
 * AlbumAdapter.
 */
public class AlbumAdapter extends BaseAdapter {

	AlbumModel album;
	Context context;
	LayoutInflater inflater;
	float width;
	
	public AlbumAdapter(Context context, AlbumModel album) {
		this.context = context;
		this.album = album;
		
		inflater = LayoutInflater.from(this.context);
		
		this.width = LayoutHelpers.convertToPx(context, Contants.PHOTO_WIDTH);
	}
	

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		// TODO Auto-generated method stub
		View item = view;
		PhotoHolder holder;
		
		if(item == null) {
			item = inflater.inflate(R.layout.photo_item, null);
			
			holder = new PhotoHolder();
			holder.image = (ImageView)item.findViewById(R.id.img);
			
			item.setTag(holder);
		}
		else {
			holder = (PhotoHolder)item.getTag();
		}
		
		PhotoModel photo = this.album.getPhoto(position);
		
		BitmapHelpers.loadBitmap(
				photo.getPath(), 
				holder.image, 
				this.width,
				this.width);
		
		return item;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return album.getPhotos().size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return album.getPhotos().get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}


}
